package com.bw.module_service.ui.polling

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.databinding.DataBindingUtil.setContentView
import com.alibaba.android.arouter.facade.annotation.Route
import com.bw.lib_common.arouter.Router
import com.bw.lib_common.base.BaseActivity
import com.bw.module_service.R
import com.bw.module_service.adapter.TaskPollingAdapter
import com.bw.module_service.databinding.ActivityTaskDetailsBinding
import com.bw.module_service.model.InspectionModel
import com.bw.module_service.model.InspectionModelItem
import com.bw.module_service.model.PollingEntity
import com.bw.module_service.model.TaskEntity
import com.bw.module_service.viewmodel.ServiceViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path =Router.Ui.TaskDetailsActivity )
class TaskDetailsActivity : BaseActivity<ServiceViewModel,ActivityTaskDetailsBinding>() {
    override val mLayoutResId: Int
        get() = R.layout.activity_task_details
    private lateinit var taskPollingAdapter: TaskPollingAdapter
    val list= mutableListOf<InspectionModelItem>()

    private val mViewModel: ServiceViewModel by viewModels()
    override fun initData() {
        mViewModel.getPatrolPoints()
        mViewModel.inspectionLiveData_.observe(this){
            list.clear()
            list.addAll(it)
            mBinding.rv.adapter?.notifyDataSetChanged()
        }

    }

    override fun initView() {
        mBinding.back.setOnClickListener {
            finish()
        }
        taskPollingAdapter= TaskPollingAdapter(list)
        mBinding.rv.layoutManager= androidx.recyclerview.widget.LinearLayoutManager(this)
        mBinding.rv.adapter=taskPollingAdapter
        val task =  intent.getSerializableExtra("task") as TaskEntity
        mBinding.taskname.text=task.taskName
        mBinding.time.text=task.patrolTime
        if (task.patrolStatus==1){
            mBinding.patrolStatus.text ="巡检中"
        }
        if (task.patrolStatus==0){
            mBinding.patrolStatus.text ="未巡检"
        }
        if (task.patrolStatus==2){
            mBinding.patrolStatus.text ="已完成"
        }
        if (task.patrolStatus==3){
            mBinding.patrolStatus.text ="已作废"
        }
    }

}